package cn.com.huzo.repository.tech.impl;

import cn.com.huzo.model.entities.tech.MrpFeedingLinesEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import cn.com.huzo.repository.tech.MrpFeedingLinesRepository;
import java.util.HashMap;

/**
 * 补料单明细数据访问对象。
 *
 * @author 吴旭
 */
@Repository("MrpFeedingLinesRepository")
public class MrpFeedingLinesRepositoryImpl extends GenericRepositoryImpl<MrpFeedingLinesEntity, String>
        implements MrpFeedingLinesRepository {

    private final String namespace = "cn.com.huzo.repository.tech.MrpFeedingLinesRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public MrpFeedingLinesRepositoryImpl() {
        super(MrpFeedingLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<MrpFeedingLinesEntity> fetchByHeaderKey(Long headerId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByHeaderKey"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<MrpFeedingLinesEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchInsert(List<MrpFeedingLinesEntity> itemList) {
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchInsert"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertFromClipboard(Map<String, Object> criterion) {
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertFromClipboard"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer importLinesFromOtherBill(Long headerId, Long importedBillHeaderId, Integer maxOrderNo, Long updatedBy) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("ImportedBillHeaderId", importedBillHeaderId);
        criterion.put("MaxOrderNo", maxOrderNo);
        criterion.put("CreatedBy", updatedBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "importLinesFromOtherBill"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<MrpFeedingLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesByMaterialId(String linesId, Long materialId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("LinesId", linesId);
        criterion.put("MaterialId", materialId);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesByMaterialId"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(String key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchDelete(List<MrpFeedingLinesEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchdelete"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer resetLinesOrder(Long headerId) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "resetLinesOrder"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesOrder(List<MrpFeedingLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesOrder"), itemList);
    }
}
